package com.example.springboot3demo.controller;

import cn.hutool.core.collection.ListUtil;
import com.example.springboot3demo.entity.dto.TestParamDTO;
import com.example.springboot3demo.entity.vo.TestListVo;
import com.example.springboot3demo.service.impl.TestService;
import com.example.springboot3demo.service.lock.RedisLock;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "Test Controller")
@RestController
@RequestMapping("/test")
@RequiredArgsConstructor
public class TestController {


    private final TestService testService;

    @Operation(summary = "test列表", description = "test列表")
    @GetMapping("/list")
    @RedisLock(key = "'avatar_trait_' + #dto.firstName", tryLok = true, tryTime = 5, lockTime = 0)
    public List<TestListVo> testList(@Validated TestParamDTO dto) {
        return ListUtil.list(false, TestListVo.builder().firstName("test").build());
    }


    @Operation(summary = "testRetry测试", description = "testRetry测试")
    @GetMapping("/testRetry")
    public void testRetry() {
        testService.testRetry();
    }

}
